//
//  NYRegisterViewController.m
//  NYTYY
//
//  Created by MinLison on 2017/12/12.
//  Copyright © 2017年 NYtyy. All rights reserved.
//

#import "NYRegisterViewController.h"
#import "NYUserRegisterRequest.h"
#import "NYSetPwdViewController.h"
#import "NYRegisterNotNewUserViewController.h"
#import "NYFormLoginViewController.h"

#import "NYAgreementViewController.h"


@interface NYRegisterViewController ()

@property (nonatomic, strong) QMUIButton *rightButton;

@end

@implementation NYRegisterViewController

- (void)viewDidLoad
{
        [super viewDidLoad];
        
}
- (void)configNavigationBar:(BaseNavigationBar *)navigationBar
{
        
        [super configNavigationBar:navigationBar];
        self.title = @"注册";
        self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:self.rightButton];
}

/// MARK: - Action
- (void)next
{
        // 注册
}
- (void)userLogin
{
        [self popToControllerClass:[NYFormLoginViewController class]];
}
- (void)userRegister
{
        @weakify(self);
        [NYUserManager registerWithParam:nil success:^(NYUserModel * _Nonnull user) {
                @strongify(self);
                [NYTipClass showText:@"注册成功"].willHideBlock = ^(UIView *hideInView, BOOL animated) {
                        @strongify(self);
                        [self.navigationController popToRootViewControllerAnimated:YES];
                };
                
        } failed:^(NSError * _Nonnull error) {
                @strongify(self);
                [NYTipClass showText:error.localizedDescription inView:self.view];
        }];
}
- (void)readAgreement
{
        //        [self routeUrl:kNYWebViewControllerURI param:@{
        //                                                       kRequestKeyUrl : APP_USER_AGREEMENT
        //                                                       }];
}
- (void)getSmsCode
{
        @weakify(self);
        [NYUserManager getSMSWithParam:@{
                                         kRequestKeyIsExist : @(1)
                                         } success:^(NSString * _Nonnull sms) {
                @strongify(self);
                [NYTipClass showText:sms inView:self.view];
        } failed:^(NSError * _Nonnull error) {
                @strongify(self);
                [NYTipClass showText:error.localizedDescription inView:self.view];
        }];
}
- (void)goToTheAgreementViewController {
      
        [self.navigationController pushViewController:[NYAgreementViewController webViewControllerWithUrlString:@"http://api.niuwaketang.com/agreement/"] animated:true];
}

//MARK: Setter and getter
- (QMUIButton *)rightButton {
        if (!_rightButton)
        {
                _rightButton = [[QMUIButton alloc] qmui_initWithImage:nil title:@"服务协议"];
                [_rightButton addTarget:self action:@selector(goToTheAgreementViewController) forControlEvents:UIControlEventTouchUpInside];
                [_rightButton setTitleColor:UIColorHex(0x5396FF) forState:0];
                _rightButton.titleLabel.font = UIFontMake(15);
        }
        return _rightButton;
}

@end
